package sctu.edu.java.year2016.team03.liyouhong.day20160605.chapter11_3;

/**
 * Created by Administrator on 2016/6/5 0005.
 * 3.创建computer类，该类中有一个计算最大公约数的方法，如果向该方法传递负整数，该方法就会抛出自定义异常。
 */
public class Computer {
    public void divisor(int a, int b) throws NumberCannotNegativeException {
        if (a < 0 || b < 0) {
            throw new NumberCannotNegativeException();
        } else {
            int c = a % b;
            int t;
            if (a < b) {
                t = b;
                b = a;
                a = t;

            }
            while (c != 0) {
                a = b;
                b = c;
                c = a % b;

            }

            System.out.println("The largest divisor:"+b);
        }

    }

    public static void main(String[] args) {
        try {
            Computer computer = new Computer();
            computer.divisor(20, 1);
        } catch (NumberCannotNegativeException e) {
            e.printStackTrace();
        }

    }
}
